Add a has-selection property
authorMatthias Clasen <matthiasc@src.gnome.org>
Fri, 7 Oct 2005 03:38:57 +0000 (03:38 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 7 Oct 2005 03:38:57 +0000 (03:38 +0000)
ChangeLog
ChangeLog.pre-2-10
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtktextbuffer.c
gtk/gtktextbuffer.h

index df044fb64e5ab7ee96f7b60d07ecd6e5c126d6f8..61ced09aad99a252ff6a8ec85ccc8ee3c28f0ce2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-10-06  Matthias Clasen  <mclasen@redhat.com> 
+               
+       * gtk/gtk.symbols:
+       * gtk/gtktextbuffer.h:
+       * gtk/gtktextbuffer.c: Add a readonly has-selection property
+       with a getter.  (#318161, Paolo Borelli)
+
 2005-10-05  Matthias Clasen  <mclasen@redhat.com>
 
        * README.in: Start collecting release notes for 2.10.
index df044fb64e5ab7ee96f7b60d07ecd6e5c126d6f8..61ced09aad99a252ff6a8ec85ccc8ee3c28f0ce2 100644 (file)
@@ -1,3 +1,10 @@
+2005-10-06  Matthias Clasen  <mclasen@redhat.com> 
+               
+       * gtk/gtk.symbols:
+       * gtk/gtktextbuffer.h:
+       * gtk/gtktextbuffer.c: Add a readonly has-selection property
+       with a getter.  (#318161, Paolo Borelli)
+
 2005-10-05  Matthias Clasen  <mclasen@redhat.com>
 
        * README.in: Start collecting release notes for 2.10.
index f84396a8f043ffefdda7acd388e5052381dbd40c..96a1370f51a48b78dc0fb87987961413f7b1b794 100644 (file)
@@ -1,3 +1,7 @@
+2005-10-06  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk-sections.txt: Add gtk_text_buffer_get_has_selection().
+
 2005-10-05  Federico Mena Quintero  <federico@ximian.com>
 
        * gtk/tmpl/gtkfilechooser.sgml: Document the "quick-bookmark"
index f7d65bcfcd45dad3f10bf965ab6df8f4569e8414..42cf1133e32d211d7ecacdcea877f917e35044a0 100644 (file)
@@ -3079,6 +3079,7 @@ gtk_text_buffer_delete_mark_by_name
 gtk_text_buffer_get_mark
 gtk_text_buffer_get_insert
 gtk_text_buffer_get_selection_bound
+gtk_text_buffer_get_has_selection
 gtk_text_buffer_place_cursor
 gtk_text_buffer_select_range
 gtk_text_buffer_apply_tag
index 020f1f0a18d39c91af0f53a72ac869d301c4c1f7..8105fcaf6cdb01d34af08d1af9a72b72c0c6daf0 100644 (file)
@@ -2873,6 +2873,7 @@ gtk_text_buffer_end_user_action
 gtk_text_buffer_get_bounds
 gtk_text_buffer_get_char_count
 gtk_text_buffer_get_end_iter
+gtk_text_buffer_get_has_selection
 gtk_text_buffer_get_insert
 gtk_text_buffer_get_iter_at_child_anchor
 gtk_text_buffer_get_iter_at_line
index 398993170fcfef65542d13f25056428b8262b427..6dd858d4f344b35611ed05638f3697aaa6977f3c 100644 (file)
@@ -41,6 +41,7 @@
 #include "gtkintl.h"
 #include "gtkalias.h"
 
+
 typedef struct _ClipboardRequest ClipboardRequest;
 
 struct _ClipboardRequest
@@ -75,7 +76,8 @@ enum {
   PROP_TAG_TABLE,
   
   /* Normal */
-  PROP_TEXT
+  PROP_TEXT,
+  PROP_HAS_SELECTION
 };
 
 enum {
@@ -113,6 +115,9 @@ static void gtk_text_buffer_real_remove_tag            (GtkTextBuffer     *buffe
                                                         const GtkTextIter *start_char,
                                                         const GtkTextIter *end_char);
 static void gtk_text_buffer_real_changed               (GtkTextBuffer     *buffer);
+static void gtk_text_buffer_real_mark_set              (GtkTextBuffer     *buffer,
+                                                        const GtkTextIter *iter,
+                                                        GtkTextMark       *mark);
 
 static GtkTextBTree* get_btree (GtkTextBuffer *buffer);
 static void          free_log_attr_cache (GtkTextLogAttrCache *cache);
@@ -180,6 +185,7 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass)
   klass->apply_tag = gtk_text_buffer_real_apply_tag;
   klass->remove_tag = gtk_text_buffer_real_remove_tag;
   klass->changed = gtk_text_buffer_real_changed;
+  klass->mark_set = gtk_text_buffer_real_mark_set;
 
   /* Construct */
   g_object_class_install_property (object_class,
@@ -208,6 +214,21 @@ gtk_text_buffer_class_init (GtkTextBufferClass *klass)
                                                        "",
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkTextBuffer:has-selection:
+   *
+   * Whether the buffer has some text currently selected.
+   *
+   * Since: 2.10
+   */
+  g_object_class_install_property (object_class,
+                                   PROP_HAS_SELECTION,
+                                   g_param_spec_boolean ("has-selection",
+                                                         P_("Has selection"),
+                                                         P_("Whether the buffer has some text currently selected"),
+                                                         FALSE,
+                                                         G_PARAM_READABLE));
+
   signals[INSERT_TEXT] =
     g_signal_new (I_("insert_text"),
                   G_OBJECT_CLASS_TYPE (object_class),
@@ -446,6 +467,10 @@ gtk_text_buffer_get_property (GObject         *object,
       break;
     }
 
+    case PROP_HAS_SELECTION:
+      g_value_set_boolean (value, text_buffer->has_selection);
+      break;
+
     default:
       break;
     }
@@ -2196,6 +2221,28 @@ gtk_text_buffer_real_changed (GtkTextBuffer *buffer)
   gtk_text_buffer_set_modified (buffer, TRUE);
 }
 
+static void
+gtk_text_buffer_real_mark_set (GtkTextBuffer *buffer,
+                               const GtkTextIter *iter,
+                               GtkTextMark *mark)
+{
+  if (mark == gtk_text_buffer_get_insert (buffer) ||
+      mark == gtk_text_buffer_get_selection_bound (buffer))
+    {
+      gboolean has_selection;
+
+      has_selection = gtk_text_buffer_get_selection_bounds (buffer,
+                                                            NULL,
+                                                            NULL);
+
+      if (has_selection != buffer->has_selection)
+        {
+          buffer->has_selection = has_selection;
+          g_object_notify (G_OBJECT (buffer), "has-selection");
+        }
+    }
+}
+
 static void
 gtk_text_buffer_emit_tag (GtkTextBuffer *buffer,
                           GtkTextTag *tag,
@@ -2698,6 +2745,24 @@ gtk_text_buffer_set_modified (GtkTextBuffer      *buffer,
     }
 }
 
+/**
+ * gtk_text_buffer_get_has_selection:
+ * @buffer: a #GtkTextBuffer 
+ * 
+ * Indicates whether the buffer has some text currently selected.
+ * 
+ * Return value: %TRUE if the there is text selected
+ *
+ * Since: 2.10
+ **/
+gboolean
+gtk_text_buffer_get_has_selection (GtkTextBuffer *buffer)
+{
+  g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
+
+  return buffer->has_selection;
+}
+
 
 /*
  * Assorted other stuff
index daac40831ccddb7854833435846b58acaa66d6c1..04aac94f0a0ee46e550f1ca5762e9d640c609aa2 100644 (file)
@@ -70,6 +70,8 @@ struct _GtkTextBuffer
   
   /* Whether the buffer has been modified since last save */
   guint modified : 1;
+
+  guint has_selection : 1;
 };
 
 struct _GtkTextBufferClass
@@ -337,6 +339,8 @@ gboolean        gtk_text_buffer_get_modified            (GtkTextBuffer *buffer);
 void            gtk_text_buffer_set_modified            (GtkTextBuffer *buffer,
                                                          gboolean       setting);
 
+gboolean        gtk_text_buffer_get_has_selection       (GtkTextBuffer *buffer);
+
 void gtk_text_buffer_add_selection_clipboard    (GtkTextBuffer     *buffer,
                                                 GtkClipboard      *clipboard);
 void gtk_text_buffer_remove_selection_clipboard (GtkTextBuffer     *buffer,